package basic;

/*
 * BufferedImageTranscoder.java
 *
 * Created on 13 March 2003, 14:09
 */

/**
 *
 * @author  hayesd
 */
/*****************************************************************************
 * Copyright (C) The Apache Software Foundation. All rights reserved.        *
 * ------------------------------------------------------------------------- *
 * This software is published under the terms of the Apache Software License *
 * version 1.1, a copy of which has been included with this distribution in  *
 * the LICENSE file.                                                         *
 *****************************************************************************/

//package org.apache.batik.transcoder.image;

import java.awt.Color;
import java.awt.image.BufferedImage;

import org.apache.batik.transcoder.image.ImageTranscoder;
import org.apache.batik.transcoder.TranscoderException;
import org.apache.batik.transcoder.TranscoderOutput;

/**
 * This class is an <tt>ImageTranscoder</tt> that produces a BufferedImage.
 * 
 * @author <a href="mailto:d.hayes@abm-uk.com">David Hayes</a>
 * 
 */
public class BufferedImageTranscoder extends ImageTranscoder {

	// Contains the last rendered BufferedImage. A solution found to obtain the
	// image after the Transcode() step in ImageTranscoder

	/** The bi last. */
	private BufferedImage biLast = null;

	/**
	 * Constructs a new transcoder that produces BufferedImage images.
	 */

	public BufferedImageTranscoder() {
		hints.put(ImageTranscoder.KEY_BACKGROUND_COLOR, Color.white);
	}

	/**
	 * Creates a new ARGB image with the specified dimension.
	 * 
	 * @param width
	 *            the image width in pixels
	 * @param height
	 *            the image height in pixels
	 * @return the buffered image
	 */
	public BufferedImage createImage(int width, int height) {
		return new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
	}

	// Note this method does not need the Transcoder Output. It allows you to
	// loosly assume that TranscoderOutput is of type
	// BufferedImageTranscoderOutput, purely because it doesn't really care.

	/**
	 * Writes the specified image to the specified output.
	 * 
	 * @param img
	 *            the image to write
	 * @param output
	 *            the output where to store the image
	 * @throws TranscoderException
	 *             the transcoder exception
	 */
	public void writeImage(BufferedImage img, TranscoderOutput output)
			throws TranscoderException {
		biLast = img;
	}

	/**
	 * Gets the last rendered.
	 * 
	 * @return the last rendered
	 */
	public BufferedImage getLastRendered() {
		return biLast;
	}
}